package com.tree.web;

import com.tree.entity.Flower;
import com.tree.entity.Rtree;
import com.tree.service.FlowerService;
import com.tree.util.HttpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping(value = "flower")
public class FlowerController {

    @Autowired
    private FlowerService flowerService;

    @RequestMapping(value = "/getlist")
    private String getList(ModelMap modelMap, HttpServletRequest request){

        //获取当前页数
        int rowIndex = HttpUtil.getInt(request,"rowIndex");
        List<Flower> list = new ArrayList<>();
        list = flowerService.queryAll(rowIndex,10);
        modelMap.addAttribute("list",list);
        modelMap.addAttribute("rowIndex",rowIndex);
        return "flower/flowers";
    }
    @RequestMapping(value = "/show")
    private String show(ModelMap modelMap, HttpServletRequest request){
        Flower flower = flowerService.query(HttpUtil.getString(request,"flowerName"));
//        System.out.println(HttpUtil.getString(request,"treeName"));
        modelMap.addAttribute("flower",flower);
        return "flower/flower";
    }
}
